class userModel{
  constructor(){
    this.db = require('../../config/db')
  }
  //获取所有用户信息
  users(){
    let sql = 'select * from user'
    return this.db.query(sql)
  }

  //查询用户
  queryUsers(query,pagenum,pagesize){
    let sql = 'select * from user'
    if(query != null || query != ""){
      sql = sql + " where username like '%"+ query+"%'"
    }
    sql += " limit ?,?"
    console.log(sql)
    return this.db.query(sql,[pagenum,pagesize])
    
  }

  //添加用户
  addUser(account,username,password,email,phone,position,sdtnbr){
    let sql = "insert into user (account,username,password,email,phone,position,sdtnbr) values (?,?,?,?,?,?,?)"
    return this.db.query(sql,[account,username,password,email,phone,position,sdtnbr])
  }
  //查询用户
  queryAddUser(account){
    let sql = "select * from user where account = ?"
    return this.db.query(sql,[account])
  }

  //修改用户数据
  updateUser(account,username,password,email,phone,position,sdtnbr,id){
    let sql = "update user set account = ?,username = ?,password = ?,email = ?,phone = ?,position = ?,sdtnbr = ? where id = ?"
    return this.db.query(sql,[account,username,password,email,phone,position,sdtnbr,id])
  }
  //修改用户数据2
  updateUseres(username,phone,email,id){
    let sql = "update user set username = ?,phone = ?,email = ? where id = ?"
    return this.db.query(sql,[username,phone,email,id])
  }
  //删除用户
  deleteUser(id){
    let sql = 'delete from user where id = ?'
    return this.db.query(sql,[id])
  }
  
}

module.exports = new userModel()